package com.module.retrofit.utils;


import com.module.retrofit.ApplicationHelper;

import java.io.Serializable;

import androidx.annotation.Nullable;

/**
 * @Author: dengqi
 * @CreateDate: 2020-10-17 10:53
 * @Description:
 */
public class CacheUtil {

    public static void saveField(@Nullable String key, @Nullable String value) {
        ACache mCache = ACache.get(ApplicationHelper.getContext());
        mCache.put(key, value);
    }

    public static String getFieldAsString(@Nullable String key) {
        ACache mCache = ACache.get(ApplicationHelper.getContext());
        return mCache.getAsString(key);
    }

    public static boolean clearField(@Nullable String key) {
        ACache mCache = ACache.get(ApplicationHelper.getContext());
        return mCache.remove(key);
    }

    /**
     * 保存实体类（以后换成数据库）
     * @param key
     * @param value
     */
    public static void saveField(@Nullable String key, @Nullable Object value) {
        ACache mCache = ACache.get(ApplicationHelper.getContext());
        mCache.put(key, (Serializable) value);
    }

    public static Object getFieldAsObject(@Nullable String key) {
        ACache mCache = ACache.get(ApplicationHelper.getContext());
        return mCache.getAsObject(key);
    }





}
